Skip to content

fix(change-note-types): don't discard undo queue#20249

Open
david-allison wants to merge 1 commit intoankidroid:mainfrom
david-allison:fix-note-types
Open

fix(change-note-types): don't discard undo queue#20249
david-allison wants to merge 1 commit intoankidroid:mainfrom
david-allison:fix-note-types

Conversation

@david-allison
Copy link
Member

@david-allison david-allison commented Jan 28, 2026

Purpose / Description

The backend method changeNotetypeOfNotes internally updates the schema does not not discard the undo queue.

https://github.com/ankitects/anki/blob/83c615cc7f9aef3c336936fa797671965538f89c/rslib/src/notetype/notetypechange.rs#L216-L222

Before this PR, we called modSchema(), which updated the schema and discarded the undo/study queues

Fixes

Approach

Upstream Anki relies on implicit knowledge to handle backend methods which update the schema: they show a dialog if a schema change is needed, then call the backend method

I attempted to introduce a 'guard context' (my terminology), using Kotlin's experimental context parameters so this check was enforced by code, but there was a dex issue:

Note

We can now add an issue, this should be fized in Kotlin 2.3.0

So I continued using Anki's approach: call launchCatchingRequiringOneWaySync before a backend method which modifies the collection

I then removed the modSchema(check = true) call

How Has This Been Tested?

Screenshot 2026-01-28 at 17 12 04

Learning (optional, can help others)

Loads of stuff in the stacked PR

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison added the Blocked by dependency Currently blocked by some other dependent / related change label Jan 28, 2026
@ZornHadNoChoice
Copy link

How Has This Been Tested?

541754429-d87f4359-0162-4ea7-a146-8316ac793676

In case you didn't know, you can undo the note type change without this PR.

@david-allison
Copy link
Member Author

I wasn't aware, but the 'one-way sync' icon now disappears when the undo occurs.

@david-allison david-allison added this to the 2.24 release milestone Jan 29, 2026
Copy link
Member

@Haz3-jolt Haz3-jolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!!

@Haz3-jolt Haz3-jolt added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jan 29, 2026
@david-allison david-allison marked this pull request as draft January 29, 2026 22:46
@david-allison david-allison removed the Blocked by dependency Currently blocked by some other dependent / related change label Mar 3, 2026
@david-allison david-allison marked this pull request as ready for review March 3, 2026 23:53
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Mar 3, 2026
The backend method `changeNotetypeOfNotes` internally updates
 the schema does not not discard the undo queue.

https://github.com/ankitects/anki/blob/83c615cc7f9aef3c336936fa797671965538f89c/rslib/src/notetype/notetypechange.rs#L216-L222

Before this PR, we called `modSchema()`, which updated the schema
 and discarded the undo/study queues

Upstream Anki relies on implicit knowledge to handle
 backend methods which update the schema: they show a dialog
 if a schema change is needed, then call the backend method

I attempted to introduce a 'guard context' (my terminology),
 using Kotlin's experimental context parameters so this check
 was enforced by code, but there was a dex issue: 20247

So I continued using Anki's approach: call
 `launchCatchingRequiringOneWaySync` before a backend method
 which modifies the collection

I then removed the `modSchema(check = true)` call

Fixes 20172
@david-allison david-allison removed Needs Author Reply Waiting for a reply from the original author Has Conflicts labels Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Second Approval Has one approval, one more approval to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing note types from the dialog breaks the undo stack

3 participants